package com.example.teesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.teesystem.entity.ExamEvaluation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author NieYaShi
* @description 针对表【t_exam_evaluation】的数据库操作Mapper
* @createDate 2022-04-19 14:44:43
* @Entity com.example.teesystem.entity.ExamEvaluation
*/
@Mapper
public interface ExamEvaluationMapper extends BaseMapper<ExamEvaluation> {
    @Select("select * from t_exam_evaluation where paper_id = #{paperId} and student_id = #{studentId} ;")
    ExamEvaluation getEvaluationByPaperAndUserId(int paperId, int studentId);

    @Update("update t_exam_evaluation set is_publish = 1 where paper_id = #{paperId} and student_id = #{studentId}")
    void publishMarkedPaper(int paperId, int studentId);

    @Select({
            "<script>"+
            "select student_id from t_exam_evaluation where is_mark = 1 and paper_id = #{paperId} and student_id in " +
            "<foreach item = 'item' index = 'index' collection = 'ids' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>"+
            "</script>"
    })
    List<Integer> getMarkedStudentIdByPaperId(int paperId, List<Integer> ids);


    @Select({
            "<script>"+
                    "select * from t_exam_evaluation where paper_id = #{paperId} and student_id in " +
                    "<foreach item = 'item' index = 'index' collection = 'ids' open='(' separator=',' close=')'>" +
                    "#{item}" +
                    "</foreach>"+
                    "</script>"})
    List<ExamEvaluation> getExamEvaluationsByStudentIds(int paperId,List<Integer> ids);

    @Select("select * from t_exam_evaluation where student_id = #{studentId} and is_mark = 1 and is_publish = 1")
    List<ExamEvaluation> getStudentMarkedExamEvaluation(int studentId);

    @Select("select * from t_exam_evaluation where paper_id = #{paperId}")
    List<ExamEvaluation> getEvaluationsByPaperId(int paperId);

    @Select("select paper_id from t_exam_evaluation where student_id = #{studentId}")
    List<Integer> getExamedPaperIds(int studentId);

}




